package com.report.reportserver.controller;

import com.report.reportserver.model.User;
import com.report.reportserver.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @ ClassName: UserController
 * @ Description：返回用户信息
 * @ Modified By：
 * @ Version:
 * @ Author     ：LiYing
 * @ Date       ：Created in 16:16 2022/2/27
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    UserService userService;

    /*
    * 通过用户id查询用户
    * */
    @RequestMapping(value = "/userid")
    public @ResponseBody Object userid(Integer id){
        User user = userService.queryUserById(id);
        return user;
    }

    /*
     * 通过用户name查询用户
     * */
    @RequestMapping(value = "/username")
    public @ResponseBody Object username(HttpServletRequest request){
        String name = request.getParameter("name");
        User user = userService.queryUserByName(name);
        return user;
    }

    /*
    * 通过用户id查询用户权限
    * */
    @RequestMapping(value = "/role")
    public @ResponseBody Object role(HttpServletRequest request){
        String name = request.getParameter("name");
        int role = userService.queryRoleByName(name);
        return role;
    }

    /*
     * 登陆失败返回
     * */
    @RequestMapping(value = "/error")
    public @ResponseBody Object error(){
        return "不登陆也能看到这个";
    }
}
